﻿namespace Phone.Framework.Converters
{
    using System;
    using System.Globalization;
    using System.IO;
    using System.Windows.Data;
    using System.Windows.Media.Imaging;
    using Phone.Framework.Data;
    using System.Windows.Controls;

    public class StreamToBitmapSourceConverter : IValueConverter
    {
        public static BitmapSource Convert(Stream stream)
        {
            if (stream == null)
            {
                return null;
            }
            BitmapImage image = new BitmapImage();
            image.SetSource(stream);
            stream.Position = 0;
            return image;
        }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return Convert(value as Stream);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }


}

